package com.xhwl.logistics.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.enums.CodeEnum;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.vehicle.VehcCarSpot;
import com.xhwl.common.query.cent.vehicle.CarSpotQuery;
import com.xhwl.logistics.service.IVehcCarSpotService;
import com.xhwl.common.vo.cent.vehicle.CarSpotVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lu.Aaron
 * @since 2021-02-08
 */
//@RestController
@Api(tags = "车位")
@Slf4j
@RequestMapping("/carSpot")
public class VehcCarSpotController {
    @Autowired
    private IVehcCarSpotService vehcCarSpotService;

    @ApiOperation(value = "新增车位",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "POST")
    @ResponseBody
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ResultJson add(@RequestHeader Short industryId,@ApiParam(value = "body字段含义请看model",required = true)@RequestBody CarSpotVO carSpotVO) {

        vehcCarSpotService.add(carSpotVO,industryId);
        return  new ResultJson(true, CodeEnum.SUCCESS.getCode(),"新增成功");
    }

    @ApiOperation(value = "修改车位",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "POST")
    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResultJson update(@RequestHeader Short industryId,@ApiParam(value = "body字段含义请看model",required = true)@RequestBody CarSpotVO carSpotVO) {

        vehcCarSpotService.edit(carSpotVO,industryId);
        return  new ResultJson(true, CodeEnum.SUCCESS.getCode(),"修改成功");
    }

    @ApiOperation(value = "删除车位",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "POST")
    @ResponseBody
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ResultJson delete(@RequestHeader Short industryId,@ApiParam(value = "车位id",required = true) @RequestParam(value = "id") Integer id) {

        vehcCarSpotService.delete(id,industryId);
        return  new ResultJson(true, CodeEnum.SUCCESS.getCode(),"删除成功");
    }

    @ApiOperation(value = "车位编号唯一性检测",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "GET")
    @ResponseBody
    @Deprecated
    @RequestMapping(value = "/number-Check", method = RequestMethod.GET)
    public ResultJson numberCheck(@ApiParam(value = "车位编号",required = true) @RequestParam(value = "number") String number,
                                  @ApiParam(value = "车场id",required = true) @RequestParam(value = "parkingLotId") Integer parkingLotId) {

        return  vehcCarSpotService.numberCheck(number,parkingLotId);
    }
    @ApiOperation(value = "车位管理分页",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "POST")
    @ResponseBody
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public ResultJson carSpotPage(@RequestBody CarSpotQuery carSpotQuery) {
        Page<VehcCarSpot> vehcCarSpotPage =vehcCarSpotService.carSpotPage(carSpotQuery);
        return  new ResultJson(true, CodeEnum.SUCCESS.getCode(),"查询成功",vehcCarSpotPage);
    }
}

